<template>
	<view class="bg-rich">
		<view class="commission_top-rich">
			<view class="can_tx_rich">
				<view class="tx_jine_rich">
					<text>我的购物额度(￥)</text>
					<!-- 领取过额度且额度为0（没有过风控的） -->
					<!-- <text class="rengong" v-if="isUserReceive && balance=='0'" @click="rengongTie">人工提额</text> -->
				</view>
				<view class="can_jine_rich">
					{{balance}}
				</view>
				<view class="wenmzi-rich">可循环使用（不可提现）</view>
			</view>


			<view class="unit order-wrapper-rich">
				<view class="icon-wrapper-rich">
					<view class="icon-unit" @click="changeTab(2)" :class="is_tx==2?'active':'noactive'">
						<image src="../../static/commission/tie.png" mode="aspectFit"
							style="width: 110rpx;height: 110rpx;"></image>
						<text class="text">{{tieOrLingqu}}</text>
					</view>
					<view class="icon-unit " @click="changeTab(1)" :class="is_tx==1?'active':'noactive'">
						<image src="../../static/commission/mingxi.png" mode="aspectFit"
							style="width: 110rpx;height: 110rpx;"></image>
						<text class="text">使用明细</text>
					</view>
					<view class="icon-unit" @click="changeTab(0)" :class="is_tx==0?'active':'noactive'">
						<image src="../../static/commission/jilu.png" mode="aspectFit"
							style="width: 110rpx;height: 110rpx;"></image>
						<text class="text">额度记录</text>
					</view>
				</view>
			</view>
		</view>


		<view class="commission_top-rich" style="padding: 0 10px;">
			<view class="txList" v-if="is_tx==1">
				<scroll-view scroll-y="true" @scrolltolower="onScrollToLower" class="yj_scroll">
					<view class="txList_li" v-for="(yongjin,index) in yongjinList" :key="index">
						<view class="li_t" style="float: left;text-align: left;">
							<view class="tx_p">
								{{yongjin.source == 0?'风控':'订单消费'}}
							</view>
							<view class="tx_t">
								{{yongjin.createTime}}
							</view>
						</view>
						<view class="li_t" style="float: right;text-align: right;">
							<view class="price_p">
								{{yongjin.tradeType==0?'+':'-'}}
								{{yongjin.amount}}元
							</view>

						</view>
					</view>
					<view class="home-bottom" v-if="pageNumber_y * pageSize - total_y >= 10">
						<text style="text-align: center; font-size: 24rpx; color: #ccc;">没有更多啦～</text>
					</view>
				</scroll-view>
			</view>


			<view class="txList" v-if="is_tx==0">
				<scroll-view scroll-y="true" @scrolltolower="onScrollToLower" class="yj_scroll">
					<view class="txList_li" v-for="(yongjin,index) in applyList" :key="index">
						<view class="li_t" style="float: left;text-align: left;">
							<view class="tx_p">
								{{yongjin.mode==0?"注册领取":"提额获取"}}
							</view>
							<view class="tx_t">
								{{yongjin.createTime}}
							</view>
						</view>
						<view class="li_t" style="float: right;text-align: right;">
							<view class="price_p">
								{{yongjin.isPass == 2?'未通过':'已通过'}} {{yongjin.price}}元
							</view>

						</view>
					</view>
					<view class="home-bottom" v-if="pageNumber_y * pageSize - total_y >= 10">
						<text style="text-align: center; font-size: 24rpx; color: #ccc;">没有更多啦～</text>
					</view>
				</scroll-view>
			</view>

			<view class="txList" v-if="is_tx==2">
				<view class="ysxy">
					<image class="check_img" @click="check_stu = check_stu ? false : true"
						:src="check_stu ? '../../static/HTSCIT_YES_RICH.png' : '../../static/HTSCIT_NO_RICH.png'">
					</image>
					我同意本站
					<text @click="open_url1(3)" class="b">《个人信息查询授权》</text>
				</view>

				<button class="sub_tie" @click="sub_tie">{{tieOrLingqu}}</button>
			</view>
		</view>

		<u-modal v-model="showCountDown" class="my-count-down-modal" width="600rpx" border-radius="25"
			:title-style="{ color: 'white' }" :show-confirm-button="false">
			<view class="slot-content">
				<CircleCountDown @change="countDownChange" :timestamp="10" />
				<view class="text-tip">
					正在{{tieOrLingqu}},请稍等...
				</view>
			</view>
		</u-modal>

	</view>
</template>

<script>
	import {
		request,
		getUserId,
		checkHasShiMingRenZheng,
		getUserReceive
	} from "@/utils"
	import CircleCountDown from '@/components/circleCountDown/CircleCountDown.vue'
	export default {
		data() {
			return {
				is_tx: 2,
				pageNumber_y: 1, //页数
				pageSize: 10, //一页多少条
				yongjinList: [],
				applyList: [],
				total_y: 1,
				total_a: 1,
				balance: 0,
				check_stu: false,
				showCountDown: false,
				tieOrLingqu: '领取额度', //显示提额还是领取
				receiveResult: null,
				currentIsOldNew: 'old', //当前用户是新人还是老人，默认是老人
				userReceive: '',
				isUserReceive: false,



				//下面是没用的垃圾混淆代码
				renzhengTimeSta1111111: true, //初次请求认证时间默认是带有的，
				zhuceTimeSta11111: false, //初次请求注册时间默认是没有的
				renzhengTimeList11111: [],
				zhuceTimeStaList1111: null,
				detailOrderIdStr11111: '',
				threeTabCurrent1111: 0,
				applyGOodsList11111: [], //供货商列表
				allCardEnterSta1111: false, //默认是false，点击批量卡券入库的时候变为true
				codeAddNumsList11111: [],
				numsList11111: [],
				dataSourceBqcp1111: [],
				selectedRowKeys1111: [],
				selectedRowKeysB11111: [],
				rkVisible11111: false,
				rkjlVisible1111: false,
				lhjlVisible1111: false,
				currentStyleData22222: {},
				dataSourceStyle2222: [],
				showStyleData2222: false,
				indexTemplate2222: [],
				SVGCircleElement3ee: '',
				vshoweqwsc1111: false,
				showStyleDataInfo2222: false,
				opeCategoryList2222: [],
				leimuVisible2222: false,
				selectedRowKeys02222: [],
				selectionRows02222: [],
				selectedRowKeys133333: [],
				selectionRows13333: [],
				selectedRowKeys2333: [],
				selectionRows23333: [],
				selectedRowKeys33333: [],
				selectionRows33333: [],
				selectedRowKeys4333: [],
				selectionRows43333: [],
				curwfqwrentStyleDaterwaInfo444: {},
				currwerentStywerleDatweraInfo1444: {},
				currewerntStyleDataInfo24444: {},
				currentweStyleDytuataIwenfo34444: {},
				currenwetStdfgyleDataInfo44444: {},
				checkZfbPhone_h5444: '',
				plNafgdvfdtjyme4444: '', //四大品类的名字
				uniPdfgrtylatform444: '', //运行环境mp-alipay mp-weixin
				refgjtytrsemark555: '', //备注
				timefgjSelStr5555: '', //选择的上门时间（2023-08-31 00:00:00）
				amOdcuiofasrpm5555: '', //选择的上门时间是上午还是下午
				pageShnjlkgohowTime5555: '', //页面上用户看到的显示的时间
				paraghsdfmsw454: {},
				valhgujtueNum56756: 0,
				addrdraess56756: {}, //上门收货地址
				adawerterydressId575: 0,
				sceoyuitne57567: '',
				tntuiopId56757: '',
				weictyuratCustomer5756: '',
				yuidurtyuoy567567: false,



				//下面是没用的垃圾混淆代码
				renzhengTimeSta1111111: true, //初次请求认证时间默认是带有的，
				zhuceTimeSta11111: false, //初次请求注册时间默认是没有的
				renzhengTimeList11111: [],
				zhuceTimeStaList1111: null,
				detailOrderIdStr11111: '',
				threeTabCurrent1111: 0,
				applyGOodsList11111: [], //供货商列表
				allCardEnterSta1111: false, //默认是false，点击批量卡券入库的时候变为true
				codeAddNumsList11111: [],
				numsList11111: [],
				dataSourceBqcp1111: [],
				selectedRowKeys1111: [],
				selectedRowKeysB11111: [],
				rkVisible11111: false,
				rkjlVisible1111: false,
				lhjlVisible1111: false,
				currentStyleData22222: {},
				dataSourceStyle2222: [],
				showStyleData2222: false,
				indexTemplate2222: [],
				SVGCircleElement3ee: '',
				vshoweqwsc1111: false,
				showStyleDataInfo2222: false,
				opeCategoryList2222: [],
				leimuVisible2222: false,
				selectedRowKeys02222: [],
				selectionRows02222: [],
				selectedRowKeys133333: [],
				selectionRows13333: [],
				selectedRowKeys2333: [],
				selectionRows23333: [],
				selectedRowKeys33333: [],
				selectionRows33333: [],
				selectedRowKeys4333: [],
				selectionRows43333: [],
				curwfqwrentStyleDaterwaInfo444: {},
				currwerentStywerleDatweraInfo1444: {},
				currewerntStyleDataInfo24444: {},
				currentweStyleDytuataIwenfo34444: {},
				currenwetStdfgyleDataInfo44444: {},
				checkZfbPhone_h5444: '',
				plNafgdvfdtjyme4444: '', //四大品类的名字
				uniPdfgrtylatform444: '', //运行环境mp-alipay mp-weixin
				refgjtytrsemark555: '', //备注
				timefgjSelStr5555: '', //选择的上门时间（2023-08-31 00:00:00）
				amOdcuiofasrpm5555: '', //选择的上门时间是上午还是下午
				pageShnjlkgohowTime5555: '', //页面上用户看到的显示的时间
				paraghsdfmsw454: {},
				valhgujtueNum56756: 0,
				addrdraess56756: {}, //上门收货地址
				adawerterydressId575: 0,
				sceoyuitne57567: '',
				tntuiopId56757: '',
				weictyuratCustomer5756: '',
				yuidurtyuoy567567: false,
			}
		},
		onLoad() {
			this.getUserIsNewOrOld()
			this.yongjinList = [];
			this.applyList = [];
			this.getBalanceInfo();
			this.getBalanceTradeRecordList(this.pageNumber_y);
			this.userReceive = getUserReceive()
		},
		components: {
			CircleCountDown
		},

		methods: {
			//跳转到人工提额
			rengongTie() {
				this.$onTo(`pagesMy/rengongTie/rengongTie`)
			},
			//倒计时
			countDownChange(time) {
				console.log('---倒计时---', time);
				if (time === 0) {
					this.showCountDown = false;
					if (this.currentIsOldNew == 'old') {
						this.oldTieOverCallback()
					} else {
						this.countDownOverCallback()
					}
				}
			},
			//新用户领取
			countDownOverCallback() {
				console.log('newnew');
				console.log('反馈结果---', this.receiveResult);
				if (this.receiveResult) {
					const res = this.receiveResult;
					if (res.data && res.data.isPass == 1) {
						uni.showToast({
							icon: 'none',
							title: '领取成功，可前往额度管理查看',
							duration: 2000
						});
					} else {
						uni.showToast({
							icon: 'none',
							// title: res.data.reason,
							title: res.errorMessage || res.msg,
							duration: 4000
						});
					}
				} else {
					uni.showToast({
						icon: 'none',
						title: `领取额度失败,请一个礼拜之后再来领取`,
						duration: 3000
					});
				}
			},
			//老用户提额
			oldTieOverCallback() {
				console.log('反馈结果---', this.receiveResult);
				if (this.receiveResult) {
					const res = this.receiveResult;
					if (res.data && res.data.isPass == 1) {
						uni.showToast({
							icon: 'none',
							title: '提额申请提交成功，待反馈',
							duration: 2000
						});
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg,
							duration: 4000
						});
					}
				} else {
					uni.showToast({
						icon: 'none',
						title: `提额申请失败,请一个礼拜之后再来领取!`,
						duration: 3000
					});
				}
			},
			//一进来就走验证身份的接口（获取是新用户还是老用户）
			getUserIsNewOrOld() {
				checkHasShiMingRenZheng().then(res => {
					console.log('==进入页面就走验证新老用户接口==', res);
					let useIsRenZheng = res.checkResult;
					if (!!useIsRenZheng) {
						//认证过的
						if (res.isReceive == undefined || res.isReceive == 0) {
							this.isUserReceive = false; //用户没有领取过额度
							console.log('新用户==');
							//已认证未领取--新用户
							this.tieOrLingqu = '领取额度'
							this.currentIsOldNew = 'new'
						} else {
							this.isUserReceive = true; //用户领取过额度
							console.log('老用户==');
							//已认证已领取，额度不够还想来领取--老用户 
							this.tieOrLingqu = '申请提额'
							this.currentIsOldNew = 'old'
						}
					} {
						//没有认证的
					}
				})
			},

			changeTab(istx) {
				this.is_tx = istx
				if (istx == 1) {
					this.getBalanceTradeRecordList(1)
				} else if (istx == 0) {
					this.getBalanceApplyRecordList(1)
				}

			},

			open_url1(type) {
				this.$onTo(`pagesOther/xieyi/loginXy?type=` + type)
			},


			//获取额度信息
			getBalanceInfo() {
				request("member/mall/aliPay/balanceTradeRecord/getBalanceInfo", {
					'userId': getUserId()
				}, "POST").then((res) => {
					console.log(res);
					this.balance = res.data

				})
			},


			//获取申请记录
			getBalanceApplyRecordList(pageNumber) {
				request("member/mall/aliPay/balanceTradeRecord/getBalanceApplyRecordList", {
					'userId': getUserId(),
					'pageNumber': pageNumber,
					'pageSize': this.pageSize
				}, "POST").then((res) => {
					console.log(res);
					if (pageNumber == 1) {
						this.applyList = res.data.records;
						this.total_a = res.data.total;
					} else {
						if (pageNumber <= res.data.pages) {
							this.applyList = this.applyList.concat(res.data.records || [])
						} else {
							return
						}
					}

				})
			},

			//获取使用记录
			getBalanceTradeRecordList(pageNumber) {
				request("member/mall/aliPay/balanceTradeRecord/getBalanceTradeRecordList", {
					'userId': getUserId(),
					'pageNumber': pageNumber,
					'pageSize': this.pageSize,
					'source': this.is_tx
				}, "POST").then((res) => {
					console.log(res);
					if (pageNumber == 1) {
						this.yongjinList = res.data.records;
						this.total_y = res.data.total;
					} else {
						if (pageNumber <= res.data.pages) {
							this.yongjinList = this.yongjinList.concat(res.data.records || [])
						} else {
							return
						}
					}

				})
			},
			sub_tie(e) {
				if (this.check_stu == false) {
					uni.showToast({
						icon: "none",
						title: "请同意协议"
					})
					return false;
				}

				checkHasShiMingRenZheng()
					.then((obj) => {
						console.log('认证信息', obj);
						this.isRenZheng = obj.checkResult;
						if (this.isRenZheng) {
							console.log('1111111111');
							this.receiveResult = null;
							console.log('22222222222');
							if (obj.isReceive == undefined || obj.isReceive == 0) {
								this.currentIsOldNew = 'new' //已认证未领取额度的情况下 可直接点击领取额度 
								request("member/mall/aliPay/balanceTradeRecord/receiveBalance", {
										'uid': getUserId()
									}, "GET", true, false, [], false, false).then((res) => {
										console.log('33333333333333');
										this.showCountDown = true;
										this.receiveResult = res;
									})
									.catch((e) => {
										this.showCountDown = true;
										this.receiveResult = null;
										console.log('已认证未领取额度catch', e);
									});
							} else { //已经领取过直接进入额度 管理
								request("member/mall/aliPay/balanceTradeRecord/improveBalance", {}, "GET", true, false,
										[], false, false).then((res) => {
										console.log('555555555555555', res);
										this.showCountDown = true;
										this.receiveResult = res;
									})
									.catch((e) => {
										this.showCountDown = true;
										this.receiveResult = null;
									});
							}
						} else {
							//新增balanceType ==1  为领取注册额度类型
							this.$onTo('/pagesMy/certificates/certificates?balanceType=1');
						}
					})
					.catch(() => {
						console.log('认证信息===========');
						this.isRenZheng = false;
					});
			},

			onScrollToLower() {
				//翻页功能每次下拉需要页数加一
				if (this.is_tx == 0 || this.is_tx == 1) {
					//判断是否需要请求商品
					if (this.pageNumber_y * this.pageSize - this.total >= 10) {
						uni.showToast({
							icon: "none",
							title: "没有更多啦～",
						})
						return
					}
					this.pageNumber_y = this.pageNumber_y + 1
					this.getBalanceTradeRecordList(this.pageNumber_y);
				}

			}


		}
	}
</script>

<style lang="scss" scoped>
	.text-tip {
		text-align: center;
		margin: 30rpx 0;
	}

	/deep/.my-count-down-modal {
		.u-mask {
			background-color: rgba(255, 255, 255, 0.5) !important;
			filter: blur(6px);
			backdrop-filter: blur(6px);
		}

		.u-drawer-content {
			overflow: visible !important;
			margin-top: -20%;

			.u-mode-center-box {
				background-color: transparent;
				height: 100rpx !important;
				// background-color: rgba(0, 0, 0, 0.95) !important;
				// border: 8rpx solid black;
				overflow: visible !important;
				// box-shadow: 18rpx 18rpx 30rpx rgba(0, 0, 0, 0.2), -18rpx -18rpx 30rpx rgba(255, 255, 255, 1);
				transition: all 0.2s ease-out;
			}

			.uni-scroll-view {
				overflow: visible !important;
			}
		}

		.u-model {
			margin-top: 10rpx;
			overflow: visible !important;
			background-color: transparent;

			.u-model__title {
				display: none;
				white-space: pre-wrap;
				font-family: 'SF Pro SC', 'SF Pro Display', 'SF Pro Icons', 'PingFang SC', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
			}

			.u-model__content {
				text-align: center;

				.slot-content {
					.my-count-down {
						margin-top: -3%;

						.u-countdown-item {
							background-color: transparent !important;

							.u-countdown-time {
								font-size: 75rpx !important;
								color: #fff !important;
							}
						}
					}

					.text-tip {
						// width: 270%;
						display: block;
						color: #282828;
						margin-top: 10%;
						font-size: 40rpx;
						font-family: 'SF Pro SC', 'SF Pro Display', 'SF Pro Icons', 'PingFang SC', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
						// transform: translateX(-28%);
						font-weight: bold;
					}

					.u-countdown-colon {
						color: #fff !important;
						font-size: 40rpx !important;
					}
				}
			}
		}
	}

	uni-app {
		margin: 0;
		padding: 0;
	}

	.commission_top-rich {
		padding: 20rpx;

		.sub_tie {
			color: #fff;
			width: 80%;
			border-radius: 20px;
			// background: #269aff;
			@include global-background-color-red();

			animation: btnshake1 2s linear infinite;
			font-size: 32rpx;
			letter-spacing: 0.1em;
			margin-top: 30rpx;
		}

		@keyframes btnshake1 {
			0% {
				transform: scale(1);
				/*开始为原始大小*/
			}

			25% {
				transform: scale(1.15);
			}

			50% {
				transform: scale(1);
			}

			75% {
				transform: scale(1.15);
			}

			100% {
				transform: scale(1);
			}
		}

		.ysxy {
			color: #5a5a5a;
			padding: 20rpx 0;
			font-size: 28rpx;
			text-align: center;

		}

		.check_img {
			position: relative;
			top: 4px;
			right: 5px;
			width: 36rpx;
			height: 18px;

		}

		.b {
			margin-left: 10rpx;
			font-size: 28rpx;
			color: #bf9465;
		}
	}

	.can_tx_rich {
		box-sizing: border-box;
		padding-left: 70rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: flex-start;
		background-image: url("https://mochongzujie.oss-cn-hangzhou.aliyuncs.com/d21033f050cc4cdcbd96f16a9c5d258e.png");
		background-repeat: no-repeat;
		background-position: center center;
		background-size: 100% 100%;
		height: 400rpx;
		border-radius: 10rpx;

	}

	.tx_jine_rich {
		font-size: 36rpx;
		color: #fff;
		letter-spacing: 0.05em;
		display: inline-flex;
		justify-content: space-around;
		align-items: center;

		.rengong {
			margin-left: 30rpx;
			font-size: 28rpx;
			background-color: #ffffff;
			color: #a07c55;
			padding: 5rpx 20rpx;
			border-radius: 30rpx;
			font-weight: 600;
		}

	}

	.can_jine_rich {
		color: #fff;
		font-weight: bold;
		text-align: center;
		font-size: 80rpx;
	}

	.wenmzi-rich {
		font-size: 24rpx;
		color: #ffffff;
	}



	.txList {
		background: #fff;
		border-radius: 10rpx;
		padding: 0 20rpx;
	}

	.txList_li {
		height: 100rpx;
		padding: 20rpx 0;
		border-bottom: 1px solid #ebebeb;
	}

	.li_t {
		width: 50%;
		color: #333;
		font-size: 38rpx;
	}

	.tx_p {
		color: #333;
		font-size: 28rpx;
	}

	.tx_t {
		color: #ababab;
		font-size: 24rpx;
	}

	.price_p {
		color: #333;
		font-size: 24rpx;
		font-weight: 400;

	}

	.yj_scroll {
		box-sizing: border-box;
		padding-top: 0;
	}

	.home-bottom {
		text-align: center;
		margin: 20rpx 0;
	}


	.order-wrapper-rich {
		z-index: 3;
		margin-bottom: 20rpx;
	}

	.unit {
		background-color: #ffffff;
		box-shadow: 0px 3px 3px 0px #d8a773;
		box-sizing: border-box;
		min-height: 220rpx;
		margin: -50rpx auto 0 auto;
		width: 93%;
		padding: 10rpx 0;
		background: #ffffff;
		border-radius: 20rpx;


		.icon-wrapper-rich {
			padding: 0 45rpx;
			display: flex;
			color: #ffffff;
			align-items: center;
			justify-content: space-around;



			.active {
				color: #000;
			}

			.noactive {
				color: #9fa0a1;
			}

			.icon-unit {
				position: relative;
				padding: 10px 40px;
				border-radius: 5px;
				font-size: 22rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				letter-spacing: 0.1em;
				width: 4em;
				margin-top: 40rpx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				.text {
					white-space: nowrap;
					font-weight: bold;
					margin-top: 10rpx;
				}

				.icon {
					width: 58rpx;
					height: 58rpx;
					margin-bottom: 15rpx;
				}


				.ch {
					margin-bottom: 0;
				}
			}

			.icon-unit:nth-child(-n + 4) {
				margin-top: 0;
			}
		}
	}
</style>